import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:delivery_application/main.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_timezone/flutter_timezone.dart';

class Globs {
  //改：提示消息的名字是程序的名字
  static const appName = "Food Delivery";
  static const userPayload = "user_payload";
  static const userLogin = "user_Login";
  //加载指示器（HUD即 Heads-Up Display）），默认显示状态为 "loading..."
  static void showHUD({String status = "loading..."}) async {
    await Future.delayed(const Duration(milliseconds: 1));
    EasyLoading.show(status: status);
  }

  //隐藏加载指示器
  static void hideHUD() {
    EasyLoading.dismiss();
  }

//SharedPreferences是一种用于存储持久化数据的方式
  // static void udSet(dynamic data, String key) {
  //   var jsonStr = json.encode(data);
  //   prefs?.setString(key, jsonStr);
  // }

  // static void udStringSet(String data, String key) {
  //   prefs?.setString(key, data);
  // }

  // static void udIntSet(int data, String key) {
  //   prefs?.setInt(key, data);
  // }
  // static void udBoolSet(int data, String key) {
  //   prefs?.setBool(key, data);
  // }

  // static void udDoubleSet(double data, String key) {
  //   prefs?.setDouble(key, data);
  // }

  // static dynamic udValue(String key) {
  //   return json.decode(prefs?.get(key) as String? ?? "{}");
  // }

  // static String udValueString(String key) {
  //   return prefs?.get(key) as String? ?? "";
  // }

  // static bool udValueBool(String key) {
  //   return prefs?.get(key) as bool? ?? false;
  // }

  // static bool udValueTrueBool(String key) {
  //   return prefs?.get(key) as bool? ?? true;
  // }

  // static int udValueInt(String key) {
  //   return prefs?.get(key) as int? ?? 0;
  // }

  // static double udValueDouble(String key) {
  //   return prefs?.get(key) as double? ?? 0.0;
  // }

  // static void udRemove(String key) {
  //   prefs?.remove(key);
  // }

//获取设备的本地时区信息
  static Future<String> timeZone() async {
    try {
      return await FlutterTimezone.getLocalTimezone();
    } on PlatformException {
      return "";
    }
  }
}

class SVKey {
  //static const mainUrl = "http://localhost:3001";
  //这个就ok了
  static const mainUrl = "http://10.0.2.2:3001";
  //static const mainUrl = "http://192.168.215.202:3001";

  static const baseUrl = '$mainUrl/api/';
  static const nodeUrl = mainUrl;

  static const svLogin = '${baseUrl}login';
  static const svSignUp = '${baseUrl}sign_up';
  static const svForgotPasswordRequest = '${baseUrl}forgot_password_request';
  static const svForgotPasswordVerify = '${baseUrl}forgot_password_verify';
  static const svForgotPasswordSetNew = '${baseUrl}forgot_password_set_new';
}

class KKey {
  static const payload = "payload";
  static const status = "status";
  static const message = "message";
  static const authTocken = "auth_Tocken";
}

class MSG {
  //Please enter valide email address
  static const enterEmail = "请输入有效的邮箱";
  //Please enter password minimun 6 characters
  static const enterPassword = "密码请至少输入6个字符";

  static const enterMobile = "请输入有效的电话号码";
  //后面删掉
  static const enterAddress = "请输入有效的地址";
  static const enterName = "请输入有效的名字";
  static const enterPasswordNotMatch = "密码错误";

  static const success = "成功";
  static const fail = "失败";
}
